package org.hyh.core.security.handler;

import org.apache.commons.lang3.StringUtils;
import org.hyh.core.Exception.TokenAuthenticationException;
import org.hyh.core.model.vo.ResultVo;
import org.hyh.core.utils.ResponseUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther :hyh
 * @desc :
 * @date :2020/7/12
 */
public class handlerWhenLoginFail  implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {

//        if(exception instanceof TokenAuthenticationException){
//            ResultVo resultVo = ResultVo.buildTokenFail(exception.getMessage());
//            ResponseUtils.resetAndResponseToClient(response,resultVo,true);
//            return;
//        }


        ResultVo resultVo = ResultVo.buildFail(exception.getMessage());
        ResponseUtils.resetAndResponseToClient(response,resultVo,true);
    }
}
